This repository was archived by the owner on Oct 17, 2026. It is now read-only.
Repository navigation
feat(usage): learn from the start of past queries - #4
Merged
Merged
Conversation
Learning only helped the exact query typed before, so choosing Safari for "safari" did nothing for "sa", which is the point of learning: typing less. A past choice now lends a share of its boost to queries that share its start, and the boosts for a query are worked out once instead of once per candidate.
A one-letter query ties hundreds of names, and localizedStandardCompare on each tie cost more than matching. The folded keys are already in memory and order the same way for ties. Minimum of five interleaved release runs on the 2,000-name benchmark: 989 µs before, 704 µs after.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Learned choices only applied to the exact query. Choosing Safari for "safari" didn't help the next "sa", so learning never let anyone type less.
Approach
Usage.choiceBoosts(_:)scans the stored choices once per query:Ranking builds a
Usage.Boosteronce per keystroke and looks each candidate up in it, instead of folding the query and checking choices per candidate.Also in this PR: tie-breaks without ICU
The pre-push check failed on the debug performance gate ("s": 72 ms against 40 ms) while this machine sat at load average 48. Profiling the outlier showed one-letter queries tie hundreds of names, and each tie called
localizedStandardCompare. Ties now compare the folded keys already computed for matching. Minimum of five interleaved release runs on the 2,000-name benchmark: 989 µs on main, 704 µs here; the debug gate went from 72 ms to 15 ms under the same load. It's a separate commit so it reads on its own.Look at sceptically
localizedStandardComparefor digits ("Item 10" sorts before "Item 9") and some scripts. It only decides exact ties in score and length.aChoiceForALongerQueryLeansAShorterOneTheSameWaywas confirmed to fail on the old code (it picks Safari).Checklist
scripts/task checkpasses locally